package liy.demo.wikiproject;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;

@SpringBootApplication
@MapperScan("liy.demo.wikiproject.mapper")
@EnableCaching
public class WikiProjectApplication {
	private static final Logger LOG = LoggerFactory.getLogger(WikiProjectApplication.class);

	public static void main(String[] args) {
		SpringApplication app = new SpringApplication(WikiProjectApplication.class);
		ConfigurableApplicationContext run = app.run(args);
		ConfigurableEnvironment environment = run.getEnvironment();

		// 打印所有属性
		printAllProperties(environment);
	}

	private static void printAllProperties(ConfigurableEnvironment environment) {
		LOG.info("====== 打印所有属性 ======");
		for (PropertySource<?> propertySource : environment.getPropertySources()) {
			if (propertySource instanceof OriginTrackedMapPropertySource) {
				OriginTrackedMapPropertySource source = (OriginTrackedMapPropertySource) propertySource;
				for (String name : source.getPropertyNames()) {
					LOG.info("{}={}", name, environment.getProperty(name));
				}
			}
		}
		LOG.info("====== 属性打印完毕 ======");
	}
}